import requests
import json
from Crypto.Cipher import AES
import base64
session=requests.session()
def pkcs5_pad(data: bytes) -> bytes:
    pad_len = 16 - len(data) % 16
    return data + bytes([pad_len] * pad_len)

def aes_encrypt_to_base64(data: str, key: str) -> str:
    key_bytes = key.encode('utf-8')[:16]
    key_bytes = key_bytes.ljust(16, b'\x00')
    cipher = AES.new(key_bytes, AES.MODE_ECB)
    padded_data = pkcs5_pad(data.encode('utf-8'))
    encrypted = cipher.encrypt(padded_data)
    return base64.b64encode(encrypted).decode('utf-8')

# ================== 1. 构建str2内容 =========================
str2 = r'''{"bd_return_size":"71.5791","bd_net_type":"wifi","bd_return_time":"0.358","bd_dtime":"1754536861","list":[{"local_ip":"","url":"https://iphone.myzaker.com/zaker/interaction.php?_appid\u003dAndroidPhone\u0026_brand\u003dRedmi\u0026_clicode\u003ddrkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F\u0026_dev\u003d39\u0026_mcode\u003d782ECE9C\u0026_only_read\u003dN\u0026_os\u003d13_23013RK75C\u0026_os_name\u003d23013RK75C\u0026_udid\u003d1fb67af59b5699a6\u0026_v\u003d9.1.5\u0026_version\u003d9.08\u0026appType\u003dnormal","net_type":"wifi","req_type":"local","e_type":"2","return_time":"3.23","dtime":"1.75453683E9"},{"local_ip":"","url":"https://iphone.myzaker.com/zaker/app_style.php?_appid\u003dAndroidPhone\u0026_brand\u003dRedmi\u0026_clicode\u003ddrkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F\u0026_dev\u003d39\u0026_flag\u003d9f0369ff51876206a9b5dd33b6d91686\u0026_mcode\u003d782ECE9C\u0026_only_read\u003dN\u0026_os\u003d13_23013RK75C\u0026_os_name\u003d23013RK75C\u0026_time\u003d1754536856\u0026_udid\u003d1fb67af59b5699a6\u0026_v\u003d9.1.5\u0026_version\u003d9.08\u0026appType\u003dnormal\u0026sign_arg\u003dapp_style|_appid,_nudid,_udid,_uid,_version","net_type":"wifi","req_type":"local","e_type":"2","return_time":"3.26","dtime":"1.75453683E9"},{"local_ip":"","url":"https://iphone.myzaker.com/zaker/ar_data/ar_list.php?_appid\u003dAndroidPhone\u0026_brand\u003dRedmi\u0026_clicode\u003ddrkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F\u0026_dev\u003d39\u0026_mcode\u003d782ECE9C\u0026_only_read\u003dN\u0026_os\u003d13_23013RK75C\u0026_os_name\u003d23013RK75C\u0026_udid\u003d1fb67af59b5699a6\u0026_v\u003d9.1.5\u0026_version\u003d9.08\u0026appType\u003dnormal","net_type":"wifi","req_type":"local","e_type":"2","return_time":"3.363","dtime":"1.75453683E9"}]}'''

# ================== 2. 生成data_code(加密) =========================
key = "amJKJsirodlsd129"
data_code = aes_encrypt_to_base64(str2, key)
print(f"data_code：{data_code}")

proxies= {
  "http": "http://127.0.0.1:7890",
  "https": "http://127.0.0.1:7890"
}
# ================== 3. 请求接口 =========================
def app_net():
    url = "https://iphone.myzaker.com/urlcheck/app_net.php"
    headers = {
        "Host": "iphone.myzaker.com",
        "User-Agent": "okhttp/4.2.2"
    }
    params = {
        "_no_track": "Y"
    }
    data = {
        "data_code": data_code,
        "_os": "13_23013RK75C",
        "_icode": "d4dcd1df6253de3b",
        "_msa_oa_id": "d4dcd1df6253de3b",
        "_os_name": "23013RK75C",
        "_mcode": "782ECE9C",
        "_net": "wifi",
        "_bsize": "1080_1920",
        "_only_read": "N",
        "appType": "normal",
        "_v": "9.1.5",
        "_udid": "1fb67af59b5699a6",
        "_dev": "39",
        "_appid": "AndroidPhone",
        "_android_id": "b9d0a4eaadbef9d1",
        "_version": "9.08",
        "_brand": "Redmi"
    }

    response = session.post(url, headers=headers, params=params, data=data,proxies=proxies)
    print(response.text)
    print(response.status_code)
if __name__ == '__main__':
    app_net()